package 退出;

public class thdexit {
    public static void main(String[] args) throws InterruptedException{
        T t = new T();
        t.start();
        //让主线程休眠十秒再退出
        Thread.sleep(10000);
        t.setLoop(false);
        t.interrupt();
        

    }
}
 class T extends Thread{
    int count=0;
    //设置一个控制变量
    private boolean loop = true;
    
    public boolean isLoop() {
        return loop;
    }

    public void setLoop(boolean loop) {
        this.loop = loop;
    }

    @Override
    public void run() {
        while(loop){
            System.out.println("狗叫"+(++count));
            try{
                Thread.sleep(500);
            }catch(InterruptedException e){
                e.printStackTrace();
            }
        }
    }
 }